<?php
/**
 * Template Name: Venues
 */

get_header(); ?>

<div class="container">
    <h1><?php the_field('name'); ?></h1>

    <div class="row-fluid">
        <div class="span8">

            <?php $image = wp_get_attachment_image_src(get_field('image_1'), 'pitch-main');
            if (get_field('image_1')) {
                ?>
                <img style="margin-bottom:15px; border-radius:3px;" src="<?php echo $image[0]; ?>"
                     alt="<?php echo get_the_title(get_field('image_1')) ?>"/>
                <?php } else { ?>
                <img style="margin-bottom:15px; border-radius:3px;"
                     src="http://pitchwise.co.uk/wp-content/uploads/2012/11/PitchWise-Logo-Light-658x300.png"
                     alt="<?php echo get_field($name) ?>"/>
                <?php }?>

            <div style="margin-bottom:25px;">
                <a href="#" class="btn btn-primary">Book Now &raquo;</a>
            </div>

            <form class="form-horizontal">

                <?php printVenueDetail('Address', 'address') ?>
                <?php printVenueDetail('Website', 'website') ?>
                <?php printVenueDetail('Notes', 'notes') ?>
                <?php printVenueDetail('Contact Number', 'primary_contact_number') ?>
                <?php printVenueDetail('Email', 'primary_contact_email') ?>
                <?php printVenueDetail('Primary Contact Name', 'primary_contact_name') ?>
                <?php printVenueDetail('Changing Rooms', 'changing_rooms') ?>
                <?php printVenueDetail('Showers', 'showers') ?>
            </form>


        </div>
        <div class="span4">
            <div class="card grey">
                <h3 class="title">Location</h3>

                <div class="card-image">
                    <div id="map_canvas" style="width: 100%; height: 250px"></div>
                </div>
                <?php the_field('address'); ?>
            </div>

            <div class="card grey">
                <h3 class="title">Available Slots </h3>

                <select style="width:276px;">
                    <option>28/11/2012 (Wed)</option>
                    <option>29/11/2012 (Thu)</option>
                    <option>30/11/2012 (Fri)</option>
                    <option>01/12/2012 (Sat)</option>
                </select>

                <table id="booking-table" class="table table-striped table-condensed table-bordered">
                    <thead>
                    <tr>
                        <th>Time</th>
                        <th></th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td>10:00 - 10:45</td>
                        <td><a class="btn btn-small btn-primary">Book &raquo;</a></td>
                    </tr>
                    <tr>
                        <td>10:45 - 11:30</td>
                        <td><a class="btn btn-small btn-primary">Book &raquo;</a></td>
                    </tr>
                    <tr>
                        <td>10:00 - 10:45</td>
                        <td><a class="btn btn-small btn-primary">Book &raquo;</a></td>
                    </tr>
                    <tr>
                        <td>10:00 - 10:45</td>
                        <td><a class="btn btn-small btn-primary">Book &raquo;</a></td>
                    </tr>
                    </tbody>

                </table>
            </div>

            <div class="card grey">
                <h3 class="title">Pitches at <?php the_field('name'); ?></h3>

                <table class="table table-bordered">
                    <tbody>
                    <?
                    $venueid = $post->ID;
                    $pitch_query = new WP_Query(array('post_type' => 'pitches', 'showposts' => 100));
                    while ($pitch_query->have_posts()) : $pitch_query->the_post();
                        $pitchid = $pitch_query->post->ID;
                        $test = get_field('venue', $pitchid);
                        if ($test[0]->ID == $venueid) {
                            ?>
                        <tr>
                            <td>
                                <a href="<? echo get_permalink($pitchid); ?>"><strong><? the_field('pid', $pitchid); ?></strong> - <? the_field('size', $pitchid); ?> on <? the_field('surface', $pitchid); ?> </a>
                            </td>
                        </tr>
                            <?
                        }
                    endwhile;
                    ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>


<?php get_footer(); ?>

<script src="<?php echo get_template_directory_uri(); ?>/js/PITCHWISE.map.js"></script>
<script src="<?php echo get_template_directory_uri(); ?>/js/PITCHWISE.pitch.slots.js"></script>

<script>
    $(function () {
        var options = {
        };

        var geoMap = new PITCHWISE.map(options);
    });
</script>